package com.activitycode.util;

import android.content.Context;
import android.content.SharedPreferences;


public class SharedUtil{
	public final static String LOGIN = "Login";
	public final static String LOGINTEL = "LOGINTEL";
	public final static String CITY = "CITY";
	public final static String DISTRICT = "DISTRICT";
	public final static String CITYLOG = "CITYLOG";
	public final static String HELPTAG = "HELPTAG";
	public final static String LATLON = "LATLON";
	
	/**
	 * keep ad
	 * @param context
	 * @param name
	 */
	public static void saveUserId(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(LOGIN, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("user_id", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getUserId(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGIN, 0);
		String isOpen = sp.getString("user_id", "");
		
		return isOpen;
	}
	
	public static void saveUserName(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(LOGINTEL, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("user_name", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getUserName(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LOGINTEL, 0);
		String isOpen = sp.getString("user_name", "");
		
		return isOpen;
	}
	
	
	/**
	 * keep title
	 * @param context
	 * @param name
	 */
	public static void saveCityName(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(CITY, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("city", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getCityName(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITY, 0);
		String isOpen = sp.getString("city", "");
		
		return isOpen;
	}
	
	/**
	 * keep title
	 * @param context
	 * @param name
	 */
	public static void saveDistrictName(Context context, String isOpen)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(DISTRICT, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("district", isOpen);
	      
	      
	      editor.commit();
	 }
	
	public static String getDistrictName(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(DISTRICT, 0);
		String isOpen = sp.getString("district", "");
		
		return isOpen;
	}
	
	/**
	 * keep last
	 * @param context
	 * @param name
	 */
	public static void saveCityStatus(Context context, Boolean isOpen)
	{	      
		  SharedPreferences sp = context.getSharedPreferences(CITYLOG, 0); 		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putBoolean("open", isOpen);
	      editor.commit();
	 }
	
	public static Boolean getCityStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(CITYLOG, 0);
		Boolean isOpen = sp.getBoolean("open", true);		
		return isOpen;
	}
	
	/**
	 * keep help first
	 * @param context
	 * @param name
	 */
	public static void saveHelpStatus(Context context, Boolean isOpen,String version)
	{	      
		  SharedPreferences sp = context.getSharedPreferences(HELPTAG, 0); 		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putBoolean("open", isOpen);
	      editor.putString("version", version);
	      editor.commit();
	 }
	
	public static Boolean getHelpStatus(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		Boolean isOpen = sp.getBoolean("open", true);		
		return isOpen;
	}
	
	public static String getHelpVersion(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(HELPTAG, 0);
		String ver = sp.getString("version", "1.0.0");
				
		return ver;
	}
	
	public static void saveLatLon(Context context, String lat, String lon)
	{
	      
		  SharedPreferences sp = context.getSharedPreferences(LATLON, 0); 
		  
	      SharedPreferences.Editor editor = sp.edit();
	      editor.clear();
	      editor.putString("lat", lat);
	      editor.putString("lon", lon);
	      
	      
	      editor.commit();
	 }
	
	public static String getLat(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LATLON, 0);
		String isOpen = sp.getString("lat", "");
		
		return isOpen;
	}
	
	public static String getLon(Context context){
		Context ctx = context;
		SharedPreferences sp = ctx.getSharedPreferences(LATLON, 0);
		String isOpen = sp.getString("lon", "");
		
		return isOpen;
	}
	
}